// 一般来说，Option和Option交互，Result和Result交互。
// 但是，有时候也需要Option和Result交互，或者 Result<T,E1>和Result<T,E2>交互
// 当时返回的异常类型在不同条件下不同的时候，就需要处理多种异常类型

// 下面的例子, unwrap会返回Option::None, 而parse::<i32>().unwrap()会返回Result::Err

fn double_first(vec: Vec<&str>) -> i32 {
    let first = vec.first().unwrap(); // Generate error 1 Option::unwrap()
    2 * first.parse::<i32>().unwrap() // Generate error 2 Result::unwrap()
}

fn main() {
    let numbers = vec!["42", "93", "18"];
    let empty = vec![];
    let strings = vec!["tofu", "93", "18"];

    println!("The first doubled is {}", double_first(numbers));

    println!("The first doubled is {}", double_first(empty));
    // Error 1: the input vector is empty

    println!("The first doubled is {}", double_first(strings));
    // Error 2: the element doesn't parse to a number
}
